package org.jxht.service.impl;

import org.jxht.dao.TeaCouDao;
import org.jxht.dao.TeacherDao;
import org.jxht.dto.MajProDto;
import org.jxht.dto.StudentDto;
import org.jxht.dto.TeaCouDto;
import org.jxht.dto.TeacherDto;
import org.jxht.service.TeacherService;
import org.jxht.util.ConstantUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by huang on 2017/3/15 0015.
 */
@Service
public class TeacherServiceImpl implements TeacherService {

    @Resource
    TeacherDao teacherDao;

    @Resource
    TeaCouDao teaCouDao;
//    添加教师用户
    public void insertTeacherService(TeacherDto dto) {
        teacherDao.insertTeacherDao(dto);
    }
//    查询多条教师用户信息
    public List queryTeacherService(int requestId,String requestWay) {
        TeacherDto dto = new TeacherDto();
        if(ConstantUtils.TEA_ID.equals(requestWay)) {
            dto.setTeaId(requestId);
        }else if(ConstantUtils.MAJ_ID.equals(requestWay)){
            dto.setMajId(requestId);
        }else {
            TeaCouDto teaCouDto = new TeaCouDto();
            teaCouDto.setCouId(requestId);
            List<TeacherDto> teacherDtos;
            List<TeaCouDto> lists = teaCouDao.queryTeaCouDistinct(teaCouDto);
            if(lists.size() > 0){
                teacherDtos = new ArrayList<TeacherDto>();
                for(TeaCouDto list:lists) {
                    dto.setTeaId(list.getTeaId());
                    teacherDtos.addAll(teacherDao.queryTeacherDao(dto));
                }
                return teacherDtos;
            }
            return null;
        }
        return teacherDao.queryTeacherDao(dto);
    }
//    查询一条教师信息记录
    public TeacherDto queryTeacherServiceSingle(TeacherDto dto) {
        return (TeacherDto) teacherDao.queryTeacherDao(dto).get(0);
    }
//    更新教师信息
    public void updataTeacherService(TeacherDto dto) {
        teacherDao.updataTeacherDao(dto);
    }
//    删除教师信息
    public void deleteTeacherService(TeacherDto dto) {
        teacherDao.deleteTeacherDao(dto);
    }
}
